package com.egene.tw.ui.dialog;

import android.app.Activity;
import android.app.Dialog;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.Window;
import android.widget.LinearLayout;

import com.egene.tw.R;
import com.egene.tw.model.User;

public class ChooseSexDialog implements OnClickListener{
    private Dialog dialog;
    private View popView;
    private Activity mActivity;
    private LinearLayout ll_male;
    private LinearLayout ll_female;
    private OnSelectSexListener mListener;

    public ChooseSexDialog(Activity activity,OnSelectSexListener listener) {
        this.mActivity = activity;
        this.mListener = listener;
        popView = (View) LayoutInflater.from(mActivity).inflate(R.layout.dialog_choose_sex, null);
        ll_male = (LinearLayout) popView.findViewById(R.id.ll_male);
        ll_female = (LinearLayout) popView.findViewById(R.id.ll_female);
        dialog = new Dialog(mActivity,R.style.mask_dialog);
        dialog.setContentView(popView, new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT));
        dialog.setFeatureDrawableAlpha(Window.FEATURE_OPTIONS_PANEL, 0);

        popView.setOnClickListener(this);
        ll_male.setOnClickListener(this);
        ll_female.setOnClickListener(this);
    }

    public void show() {
        dialog.show();
    }

    public void hide() {
        dialog.dismiss();
    }

	@Override
	public void onClick(View v) {
		switch(v.getId()){
		case R.id.ll_female:
			if(mListener != null){
				mListener.onSelect(User.FEMALE);
			}
			hide();
			break;
		case R.id.ll_male:
			if(mListener != null){
				mListener.onSelect(User.MALE);
			}
			hide();
			break;
		default:
			hide();
			break;
		}
	}
    
	public interface OnSelectSexListener{
		public void onSelect(int sex);
	}

}